//
//  UserMOdel.m
//  忘不了
//
//  Created by rimi on 16/7/8.
//  Copyright © 2016年 handuan. All rights reserved.
//

#import "UserModel.h"

@implementation UserModel
+(instancetype)shareUserModel{
    static UserModel* user;
    static dispatch_once_t onceToken;//保证下面的dispatch_once(&onceToken代码只走1次
    dispatch_once(&onceToken,^{
        user = [[UserModel alloc]init];
    });
    return user;
}

//存储用户名密码
- (void)storeUserName:(NSString *)username Password:(NSString *)password {
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSDictionary *userDic = [NSDictionary dictionary];
    userDic = @{@"username":username,@"password":password};
    [userDefault setObject:userDic forKey:@"userInfo"];
    //立即存储
    [userDefault synchronize];
}

//读取用户名密码
- (NSDictionary *)readUserNameAndPassword {
   NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSDictionary *userInfo = [NSDictionary dictionary];
    userInfo = [userDefault objectForKey:@"userInfo"];
    if (userInfo != nil) {
        return userInfo;
    } else {
        return nil;
    }
    
}

@end
